
package com.ifcar.app.view;

import com.ifcar.app.util.ThemeSettingsHelper;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.widget.ImageView;

public class NewsImageView extends ImageViewTouch {

    public NewsImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public NewsImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NewsImageView(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        onDrawExtra(canvas);

    }

    protected void onDrawExtra(Canvas canvas) {
        if (ThemeSettingsHelper.getThemeSettingsHelper(getContext()).isNightTheme(getContext())) {
            canvas.drawARGB(125, 0, 0, 0);
        }
    }

    @Override
    protected void getProperBaseMatrix(RotateBitmap bitmap, Matrix matrix) {
        float viewWidth = getWidth();
        float viewHeight = getHeight();

        float w = bitmap.getWidth();
        float h = bitmap.getHeight();
        matrix.reset();

        // We limit up-scaling to 3x otherwise the result may look bad if it's
        // a small icon.
        float widthScale = Math.min(viewWidth / w, 3.0f);
        float heightScale = Math.min(viewHeight / h, 3.0f);
        float scale = Math.min(widthScale, heightScale);
        

        matrix.postConcat(bitmap.getRotateMatrix());
        matrix.postScale(scale, scale);
        
        float transX = (viewWidth - w * scale) / 2F;
        float transY = (viewHeight - h * scale) / 2F;
        if (transY < 0) {
            transY = 0;
        }
        
        matrix.postTranslate(transX, transY);
    }
    
    
}
